﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DaInterFace;
using DaInterFace.PDA;
using DaInterFace.PDA.P02;

namespace P02
{
    /// <summary>
    /// 获得取样单下的车辆信息
    /// </summary>
    public class A03 : IPDAChild
    {
        public void Code(IPDA handler, CodeResult CR, PDACodeUser user, String parameter)
        {
            P02A03P P = (P02A03P)handler.XML.Deserialize(typeof(P02A03P), parameter);

            P02A03R R = new P02A03R();
            
            try
            {
                DataTable table = new DataTable();
                table.TableName = "CARS";

                SqlParameter[] sps = new SqlParameter[1];
                sps[0] = new SqlParameter("@BillID", SqlDbType.NVarChar, 50);
                sps[0].Value = P.BillID;

                StringBuilder sql = new StringBuilder();
                sql.Append("Select A.FEntryID FID,B.FID BillID,B.FBillNo BillNo,B.FText CarNo,B.FDecimal GroQty,B.FDecimal17 RedQty,IsNUll(B.FComboBox4,'0') RedStyle,A.FTime2 SampTime From KEW_PurchSamplingEntry A\r\n");
                sql.Append("Left Join KEW_PurchInfo B On A.FID_SRC=B.FID \r\n");
                sql.Append("Where A.FID=@BillID ORDER BY A.FTime2");
                Recordset rs = handler.Data.ExeProcedure(P.BaseNo, sql.ToString(), sps);

                if (rs.Enable)
                {
                    table.Merge(rs.Data.Tables[0]);
                    R.Table = table;
                    CR.Content = handler.XML.Serializer(typeof(P02A03R), R);
                    CR.Message = String.Format("操作员{0}获取账套{1}取样单ID{2}下的车辆信息", user.UserName, P.BaseNo, P.BillID);
                }
                else
                {
                    CR.Result = EnumResult.Error;
                    CR.Message = "数据库错误";
                }
            }
            catch (Exception ex)
            {
                CR.Result = EnumResult.Error;
                CR.Message = ex.Message;
                handler.Message(MessageType.Error, String.Format("发生错误:{0}", ex.Message));
            }
        }
    }


}
